#coding=utf-8
from django import template
from django.utils.safestring import mark_safe

register = template.Library()

@register.simple_tag
def filter_all(url_info, type):
	print(url_info)
	ret = ''
	if type == 'article_type_id':
		n1 = url_info['article_type_id']
		n2 = url_info['category_id']
		if n1 == 0:
			ret = '<a class="active" href="/article-0-%s"> 全部 </a>' % (n2,)
		else:
			ret = '<a href ="/article-0-%s"> 全部 </a>' % (n2,)
	if type == 'category_id':
		n1 = url_info['category_id']
		n2 = url_info['article_type_id']

		if n1 == 0:
			ret = '<a class="active" href="/article-%s-0"> 全部 </a>' % (n2,)
		else:
			ret = '<a href ="/article-%s-0"> 全部 </a>' % (n2,)

	return mark_safe(ret)

@register.simple_tag
def filter_article_type(type_list,url_info):
	ret = []
	for row in type_list:
		if row[0] == url_info['article_type_id']:
			sample = '<a class="active" href="/article-%s-%s">%s</a>' % (row[0], url_info['category_id'], row[1])
		else:
			sample = '<a href="/article-%s-%s">%s</a>' % (row[0], url_info['category_id'], row[1])
		ret.append(sample)
	print(ret)
	return mark_safe(''.join(ret))
